import { inject, onMounted } from 'vue'
import { useCityStore } from '../../../stores/city'
import { getLocationCityHttp } from '../../../model/Http'
export const useHttpHook = () => {
    const $store = useCityStore();
    onMounted(async () => {
        const $map = inject("$map");
        console.log($map)
        // console.log($store.city)
        /* 放http请求 */

        /* 1、根据城市获取坐标 */
        let result = await getLocationCityHttp($store.city)
        let { adcode, location } = result.geocodes[0];
        /* 2、执行飞行 */
        $map.getView().animate({
            center: location.split(","),
            zoom: 10,
            duration: 3000
        })
        /* 3、加载geojson */
        let geojson_url = `https://geo.datav.aliyun.com/areas_v3/bound/${adcode}.json`
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            url: geojson_url
        })
        var layer = new ol.layer.Vector({
            source
        })
        $map.addLayer(layer);
    })
}